package com.yuanli.modules.system.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yuanli.common.api.vo.Result;
import com.yuanli.common.constant.CacheConstant;
import com.yuanli.common.desensitization.annotation.SensitiveEncode;
import com.yuanli.common.system.vo.LoginUser;
import com.yuanli.modules.system.entity.SysRoleIndex;
import com.yuanli.modules.system.entity.SysUser;
import com.yuanli.modules.system.vo.LoginUserVo;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用户表 服务类
 * </p>
 */
public interface ISysUserService extends IService<SysUser> {


    LoginUser getUserByToken(HttpServletRequest httpServletRequest);

    /**
     * 根据用户名查询
     * @param username 用户名
     * @return SysUser
     */
    public SysUser getUserByName(String username);

    /**
     * 根据手机号获取用户名和密码
     * @param phone 手机号
     * @return SysUser
     */
    public SysUser getUserByPhone(String phone);

    /**
     * 根据OpenId获取用户
     * @param openId
     * @return SysUser
     */
    public SysUser getUserByOpenId(String openId);

    @Transactional(rollbackFor = Exception.class)
    void saveUser(SysUser user, String selectedRoles, String selectedDeparts);

    @Transactional(rollbackFor = Exception.class)
    @CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, allEntries = true)
    void editUser(SysUser user, String roles, String departs);

    @CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, allEntries = true)
    @Transactional(rollbackFor = Exception.class)
    boolean deleteUser(String userId);

    @CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, allEntries = true)
    @Transactional(rollbackFor = Exception.class)
    boolean deleteBatchUsers(String userIds);

    @CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, allEntries = true)
    Result<?> changePassword(SysUser sysUser);

    Result<LoginUserVo> checkUserIsEffective(SysUser sysUser);

    @Transactional(rollbackFor = Exception.class)
    boolean removeLogicDeleted(List<String> userIds);

    @Cacheable(cacheNames= CacheConstant.SYS_USERS_CACHE, key="#username")
    @SensitiveEncode
    LoginUser getEncodeUserInfo(String username);

    Map<String, String> getDepNamesByUserIds(List<String> userIds);

    SysRoleIndex getDynamicIndexByUserRole(String username, String version);

    List<SysUser> queryLogicDeleted();

    List<SysUser> queryLogicDeleted(LambdaQueryWrapper<SysUser> wrapper);

    @CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, allEntries = true)
    boolean revertLogicDeleted(List<String> userIds, SysUser updateEntity);
}
